<template>
  <div>
    <div class="product-content-box d-md-flex">
      <img :src="info.img" alt="" class="mr-md-5" />
      <div class="product-content-right">
        <p>{{ info.name }}</p>
        <div class="detail-box" v-html="info.desc">{{ info.desc }}</div>
      </div>
    </div>
    <div class="product-pages-box">
      <div class="product-prev-box" v-show="info.previous">
        <div @click="detail(info.previous ? info.previous.id : '')">
          <span>{{ $t('last') }}：</span>
          <span>{{ info.previous ? info.previous.name : '' }}</span>
        </div>
      </div>
      <div class="product-next-box" v-show="info.next">
        <div @click="detail(info.next ? info.next.id : '')">
          <span>{{ $t('next') }}：</span>
          <span>{{ info.next ? info.next.name : '' }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  async asyncData({ params, $axios, store }) {
    const data = await $axios.$post('goods/detail', {
      language: store.state.locale,
      goods_id: params.id,
    })
    const result = JSON.parse(data).data
    return {
      info: result,
      id: params.id,
    }
  },
  methods: {
    async detail(id) {
      if (id) {
        const data = await this.$axios.$post('goods/detail', {
          language: localStorage.getItem('lang'),
          goods_id: id,
        })
      this.info = JSON.parse(data).data
      }
    },
    async getData() {
      const data = await this.$axios.$post('goods/detail', {
        language: localStorage.getItem('lang'),
        goods_id: this.id,
      })
      this.info = JSON.parse(data).data
    },
  },
  watch: {
    '$store.state.locale'() {
      this.getData()
    },
  }
}
</script>

<style lang="scss">
.product-content-box {
  width: 100%;
  box-sizing: border-box;
  padding-bottom: 20px;
  border-bottom: 1px solid #dddddd;
  margin-bottom: 25px;

  img {
    max-width: 100%;
  }

  .product-detail-box {
    max-width: 100%;

    p >>> img {
      width: 100% !important;
    }
  }

  .product-content-right {
    flex: 1;
    p {
      &:first-child {
        font-size: 20px;
      }
      &:last-child {
        font-size: 14px;
      }
    }
  }
}

.product-pages-box {
  display: flex;
  font-size: 12px;
  justify-content: space-between;
  
  .product-next-box {
    cursor: pointer;
    font-size: 12px;
    margin-left: auto;
  }

  .product-prev-box {
    cursor: pointer;
    font-size: 12px;
  }
}
</style>
